package com.ruoyi.web.controller.email;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机名称
    public static final String ITEM_TOPIC_EXCHANGE = "item_topic_exchange";
    //队列名称
    public static final String ITEM_QUEUE = "item_queue";
    //队列名称
    public static final String AUDIT_QUEUE = "audit_queue";
    //声明交换机
    @Bean("itemTopicExchange")
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange(ITEM_TOPIC_EXCHANGE).durable(true).build();
    }

    // 2.Queue 队列
    @Bean("bootQueue")
    public Queue bootQueue(){
        return QueueBuilder.durable(ITEM_QUEUE).build();
    }
    @Bean("auditQueue")
    public Queue auditQueue(){
        return QueueBuilder.durable(AUDIT_QUEUE).build();
    }
    // 3.绑定交换机队列
    // 知道那个队列,知道那个交换机,routing key
    @Bean
    public Binding bindingQueueExchange(){
        return BindingBuilder.bind(bootQueue()).to(topicExchange()).with("boot.#").noargs();
    }

    @Bean
    public Binding bindingQueueExchange1(){
        return BindingBuilder.bind(auditQueue()).to(topicExchange()).with("item.#").noargs();
    }
}
